/*** A WebRTC switch between Chrome and Firefox. Mounts appropriate
   * implementation of RTCPeerConnection, getUserMedia and attatchMediaStream
   * in adapterEnv. ***/

var adapterEnv = {
    RTCPeerConnection: null,   // The RTCPeerConnection object.
    getUserMedia     : null,   // Function that captures local user's media.
    attachMediaStream: null    // Function that attaches a media stream to an element.
}



if (navigator.mozGetUserMedia) {1
  	console.log("This appears to be Firefox");

  	adapterEnv.RTCPeerConnection = mozRTCPeerConnection;
  	adapterEnv.getUserMedia = navigator.mozGetUserMedia.bind(navigator);
  	adapterEnv.attachMediaStream = function(element, stream) {
    	console.log("Attaching media stream");
    	element.mozSrcObject = stream;
    	element.play();
  	};
} else if (navigator.webkitGetUserMedia) {
    /* Chrome */
  	console.log("This appears to be Chrome");

  	adapterEnv.RTCPeerConnection = webkitRTCPeerConnection;
  	adapterEnv.getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
  	adapterEnv.attachMediaStream = function(element, stream) {
    	element.src = webkitURL.createObjectURL(stream);
  	};
} else {
    /* Other browser - not WebRTC compatible */
  	console.log("Browser does not appear to be WebRTC-capable");
}